package com.xy.smartsms.util;

import android.content.Context;

import java.lang.reflect.Method;

/**
 * Created by weicools on 2017/7/28.
 */

public class NavBarUtil {
    // 获取NavigationBar的高度
    public static int getNavBarHeight(Context context) {
        int resourceId = context.getResources().getIdentifier("navigation_bar_height",
                "dimen", "android");
        return context.getResources().getDimensionPixelSize(resourceId);
    }

    // 判断是否存在NavigationBar
    public static boolean hasDeviceHasNavBar(Context context) {
        boolean hasNavigationBar = false;
        int id = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            hasNavigationBar = context.getResources().getBoolean(id);
        }
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method m = systemPropertiesClass.getMethod("get", String.class);
            String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
            if ("1".equals(navBarOverride)) {
                hasNavigationBar = false;
            } else if ("0".equals(navBarOverride)) {
                hasNavigationBar = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return hasNavigationBar;
    }

    /*// 通过判断设备是否有物理返回键、菜单键来确定是否有navigation bar //有缺陷
    public static boolean checkDeviceHasNavBar(Context activity) {
        //boolean hasMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap
                .deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !hasBackKey;
    }*/
}
